package api

import (
	"gateway/basic/config"
	__ "gateway/basic/proto"
	"gateway/handler/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func GetClassList(c *gin.Context) {
	var req request.LoginReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  "参数错误",
		})
		return
	}

}

func GetClassDetail(c *gin.Context) {
	var req request.GetClassDetailReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  "参数错误",
		})
		return
	}
	detail, err := config.ClassClient.GetClassDetail(c, &__.GetClassDetailReq{
		BuyStatus: int64(req.BuyStatus),
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  "客户端连接失败",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "课程详情展示成功",
		"data": detail,
	})
}

func CreateCollect(c *gin.Context) {
	var req request.CreateCollectReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  "参数错误",
		})
		return
	}
	_, err := config.ClassClient.CreateCollect(c, &__.CreateCollectReq{
		UserId:    int64(req.UserId),
		ClassesId: int64(req.ClassesId),
		TypesId:   int64(req.TypesId),
		Price:     int64(req.Price),
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  "客户端连接失败",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "收藏添加成功",
	})
}

func GetCollectDetail(c *gin.Context) {
	var req request.GetCollectDetailReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  "参数错误",
		})
		return
	}
	detail, err := config.ClassClient.GetCollectDetail(c, &__.GetCollectDetailReq{
		Id: int64(req.Id),
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  "客户端连接失败",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "收藏展示成功",
		"data": detail,
	})
}
